﻿using System.Linq;
using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace WindowsPhoneAppHost
{
    public partial class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            InitializeComponent();
            //            NavigationService.Remo
            //            NavigationService.RemoveBackEntry();

        }

        private void Image_ImageFailed(object sender, ExceptionRoutedEventArgs e)
        {

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

            MessageBox.Show("Hello world!");
        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            if (MessageBox.Show("您确定要退出本程序吗？", "提醒", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
            {
                e.Cancel = true;//操作取消
                //                Process.GetCurrentProcess().CloseMainWindow();
//                Process.GetCurrentProcess().CloseMainWindow();
                //                this.pro
            }
            //这里可以执行弹出对话框操作
            //            e.Cancel = true;
            //            MessageBox.Show("返回键不再返回");
        }

        private void Exit()
        {
//            NavigationService.BackStack
            while (NavigationService.BackStack.Any())
                NavigationService.RemoveBackEntry();
            this.IsHitTestVisible = this.IsEnabled = false;
            if (this.ApplicationBar != null)
            {
                foreach (var item in this.ApplicationBar.Buttons.OfType<ApplicationBarIconButton>())
                {
                    item.IsEnabled = false;
                }
            }
        }
    }
}